﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Data.SqlClient;
using ComModel;

namespace ComDAL
{
    public class searchdal
    {
        string constr = ConfigurationManager.ConnectionStrings["myDB"].ToString();

        public List<ContentModel> searchlist(string name)
        {
            SqlConnection conn = new SqlConnection(constr);
            conn.Open();
            string sql = string.Format("select * from tb_bbsContent where bbs_title like '%{0}%'",name);

            SqlCommand com = new SqlCommand(sql, conn);
            SqlDataReader reader = com.ExecuteReader();
            List<ContentModel> model=new List<ContentModel>();
            while (reader.Read())
	        {
                ContentModel m=new ContentModel();
                m.bbs_content=reader["bbs_content"].ToString();
                m.bbs_face=reader["bbs_face"].ToString();
                m.bbs_id=Convert.ToInt32(reader["bbs_id"]);
                m.bbs_isGood=reader["bbs_isGood"].ToString();
                m.bbs_isTop=reader["bbs_isTop"].ToString();
                m.bbs_sender=reader["bbs_sender"].ToString();
                m.bbs_sendTime=DateTime.Parse(reader["bbs_sendTime"].ToString());
                m.bbs_title=reader["bbs_title"].ToString();
                m.bbs_toGoodTime=DateTime.Parse(reader["bbs_toGoodTime"].ToString());
                m.bbs_toTopTime=DateTime.Parse(reader["bbs_toTopTime"].ToString());
                m.bbs_up=Convert.ToInt32(reader["bbs_up"]);
                m.down = Convert.ToInt32(reader["bbs_down"]);

                model.Add(m);
	        }
            conn.Close();
            return model;
        }
    }
}
